// webpack 配置文件入口
const path = require('path')

module.exports = {
  mode: 'none', // none / production / development
  entry: './src/main.js',
  output: {
    filename: 'bundle.js',
    path: path.join(__dirname, 'dist'),
    publicPath: 'dist/'
  },
  module: {
    rules: [
      {
        test: /.js$/,
        use: {
          loader: 'babel-loader',
          options: {
            presets: ['@babel/preset-env']
          }
        }
      },
      {
        test: /.css$/,
        use: [
          'style-loader',
          'css-loader' // 先执行
        ]
      },
      // {
      //     test: /.png$/,
      //     use: 'file-loader'
      // }
      {
        test: /.png$/,
        use: {
          loader: 'url-loader', // 必须安装 'file-loader'
          options: {
            limit: 10 * 1024 // 10KB --> 当文件小于10KB的时候， 使用'url-loader'去加载文件
          }
        }
      },
      {
        test: /.html$/,
        use: {
          loader: 'html-loader', // https://www.npmjs.com/package/html-loader
          options: {
            attributes: {
              list: [
                // All default supported tags and attributes
                {
                  tag: 'img',
                  attribute: 'data-src',
                  type: 'src'
                },
                {
                  tag: 'img',
                  attribute: 'data-srcset',
                  type: 'srcset'
                },
                {
                  tag: 'a',
                  // Attribute name
                  attribute: 'href',
                  // Type of processing, can be `src` or `scrset`
                  type: 'src'
                }
              ]
            }
          }
        }
      }
    ]
  }
}
